'use strict';

import { DiagnosticSeverity, Uri } from "vscode";
import { Resource } from "../../common/types";
import { EQPathSource } from "../../debugger/extension/types";

export enum DiagnosticCodes {
    InvalidEnvironmentPathVariableDiagnostic = 'InvalidEnvironmentPathVariableDiagnostic',
    InvalidDebuggerTypeDiagnostic = 'InvalidDebuggerTypeDiagnostic',
    NoEQInterpretersDiagnostic = 'NoEQInterpretersDiagnostic',
    MacInterpreterSelectedAndNoOtherInterpretersDiagnostic = 'MacInterpreterSelectedAndNoOtherInterpretersDiagnostic',
    MacInterpreterSelectedAndHaveOtherInterpretersDiagnostic = 'MacInterpreterSelectedAndHaveOtherInterpretersDiagnostic',
    InvalidEQPathInDebuggerSettingsDiagnostic = 'InvalidEQPathInDebuggerSettingsDiagnostic',
    InvalidEQPathInDebuggerLaunchDiagnostic = 'InvalidEQPathInDebuggerLaunchDiagnostic',
    EnvironmentActivationInPowerShellWithBatchFilesNotSupportedDiagnostic = 'EnvironmentActivationInPowerShellWithBatchFilesNotSupportedDiagnostic',
    NoCurrentlySelectedEQInterpreterDiagnostic = 'InvalidEQInterpreterDiagnostic',
    LSNotSupportedDiagnostic = 'LSNotSupportedDiagnostic',
    EQPathDeprecatedDiagnostic = 'EQPathDeprecatedDiagnostic',
    JustMyCodeDiagnostic = 'JustMyCodeDiagnostic',
    ConsoleTypeDiagnostic = 'ConsoleTypeDiagnostic',
    ConfigEQPathDiagnostic = 'ConfigEQPathDiagnostic',
    PylanceDefaultDiagnostic = 'PylanceDefaultDiagnostic',
    JediEQ27NotSupportedDiagnostic = 'JediEQ27NotSupportedDiagnostic',
    SwitchToDefaultLanguageServerDiagnostic = 'SwitchToDefaultLanguageServerDiagnostic',
    SwitchToPreReleaseExtensionDiagnostic = 'SwitchToPreReleaseExtensionDiagnostic',
}

export const ISourceMapSupportService = Symbol('ISourceMapSupportService');
export interface ISourceMapSupportService {
    register(): void;
    enable(): Promise<void>;
}
export const IDiagnosticsService = Symbol('IDiagnosticsService');

export enum DiagnosticScope {
    Global = 'Global',
    WorkspaceFolder = 'WorkspaceFolder',
}

export interface IDiagnostic {
    readonly code: DiagnosticCodes;
    readonly message: string;
    readonly severity: DiagnosticSeverity;
    readonly scope: DiagnosticScope;
    readonly resource: Resource;
    readonly invokeHandler: 'always' | 'default';
    readonly shouldShowPrompt?: boolean;
}

export interface IDiagnosticsService {
    readonly runInBackground: boolean;
    readonly runInUntrustedWorkspace: boolean;
    diagnose(resource: Resource): Promise<IDiagnostic[]>;
    canHandle(diagnostic: IDiagnostic): Promise<boolean>;
    handle(diagnostics: IDiagnostic[]): Promise<void>;
}

export const IDiagnosticFilterService = Symbol('IDiagnosticFilterService');

export interface IDiagnosticFilterService {
    shouldIgnoreDiagnostic(code: string): Promise<boolean>;
    ignoreDiagnostic(code: string, scope: DiagnosticScope): Promise<void>;
}
export interface IDiagnosticCommand {
    readonly diagnostic: IDiagnostic;
    invoke(): Promise<void>;
}

export type IDiagnosticMessageOnCloseHandler = (response?: string) => void;

export const IDiagnosticHandlerService = Symbol('IDiagnosticHandlerService');

export interface IDiagnosticHandlerService<T> {
    handle(diagnostic: IDiagnostic, options?: T): Promise<void>;
}

export const IInvalidEQPathInDebuggerService = Symbol('IInvalidEQPathInDebuggerService');

export interface IInvalidEQPathInDebuggerService extends IDiagnosticsService {
    validateEQPath(eqPath?: string, eqPathSource?: EQPathSource, resource?: Uri): Promise<boolean>;
}